﻿#ifndef Utest_h__2013_7_26__20_30
#define Utest_h__2013_7_26__20_30

#include "df_macro.h"

#ifdef WIN32
#	define DF_TEST_BREAK_POINT do{if(::MessageBoxA(::GetActiveWindow(),"测试失败,触发断点?","断点",MB_OKCANCEL | MB_ICONQUESTION)==IDOK)::DebugBreak();}while(0)
#else
#	define DF_TEST_BREAK_POINT 
#endif

///判断表达式结果是否为true
#define DF_TEST(_express)	if(_express)df::Utest::Success(); \
							else{ df::Utest::Failed(__FILE__, __LINE__); DF_TEST_BREAK_POINT; }

namespace df
{
	class Utest
	{

	public:

		//完成数
		static int & GetCount()
		{
			static int testCounter_ = 0;
			return testCounter_;
		}


		static void Success()
		{
			printf("\r\n测试:%d  - 通过!\r\n", GetCount()++);
		}

		static void Failed(const char * file, int line)
		{
			printf("\r\n测试:%d  - 失败! File: %s(%i)\r\n", GetCount()
				, file, line);
		}

		static void Test(bool res, const char * str, const char * file, int line)
		{
			if (res)
			{
				printf("\r\n测试:%d  - %s通过!\r\n", GetCount()++, str);
			}
			else
			{
				printf("\r\n测试:%d  - %s失败!\r\nFile: %s(%i)\r\n", GetCount()
					, str, file, line);
				DF_BREAK_POINT;
			}
		}


		DF_DISABLE_COPY_ASSIGN(Utest);
	};

}

#endif // Utest_h__2013_7_26__20_30
